package com.rookie.im.controller;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.rookie.im.minio.MinioUtils;

@RestController
public class FileController {

	private MinioUtils minioUtils;

	@Autowired
	public FileController(MinioUtils minioUtils) {
		this.minioUtils = minioUtils;
	}

	@GetMapping("/test")
	public String test() {
		return "test";
	}
	@GetMapping("/fileurl")
	public String fileurl(
			@RequestParam("filename") String filename, 
			@RequestParam("expires") Optional<Integer> expires) {
		return minioUtils.fileUrl(filename, expires.orElse(604800));
	}

	@GetMapping("/download")
	public ResponseEntity<byte[]> download(@RequestParam("filename") String filename) {
		return minioUtils.download(filename);
	}

}
